<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\TeamModel;
use App\Models\MatchModel;
class MatchController extends Controller
{
    public function matchAdd(){

   
    $data=TeamModel::get();

    return view("admin/matchAdd",['data'=>$data]);
    }


    public function matchCreate(){
    $data=request()->except("_token");
    $data['start_time']=strtotime($data['start_time']);
   $res=MatchModel::create($data);
   if($res){

    return redirect("admin/matchIndex");
   }
    }

    public function matchIndex(){

    $data=MatchModel::select('match.match_id','match.start_time','tA.team_name as tA_name','tB.team_name as tB_name')
    ->join('team as tA','match.team_one',"=",'tA.team_id')
    ->join('team as tB','match.team_two',"=",'tB.team_id')
    ->get();
          // dd($data);  
    return view("admin/matchIndex",['data'=>$data]);       
    }

}
